package com.eatme.web.app.customer.entity;

import com.eatme.web.app.coupon.common.constant.CouponCategory;
import com.eatme.web.app.coupon.common.constant.DistributeTarget;
import com.eatme.web.app.coupon.common.constant.ProductLine;
import com.eatme.web.app.coupon.common.vo.TemplateRule;
import com.eatme.web.app.coupon.template.converter.CouponCategoryConverter;
import com.eatme.web.app.coupon.template.converter.DistributeTargetConverter;
import com.eatme.web.app.coupon.template.converter.ProductLineConverter;
import com.eatme.web.app.coupon.template.converter.TemplateRuleConverter;
import com.eatme.web.app.coupon.template.serialization.CouponTemplateSerialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.persistence.*;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;

/**
 * 优惠券模板实体类定义: 基础属性 + 规则属性
 */
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(name="tb_user")
// @JsonSerialize(using = CouponTemplateSerialize.class)
public class TbUser implements UserDetails, Serializable {

    /** 自增主键 */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "user_id",nullable = false)
    private Integer userId;

    /** 用户名 */
    @Column(name = "user_name")
    private String userName;

    /** 手机号 */
    @Column(name = "moblie")
    private  String moblie;

    /** 密码 */
    @Column(name = "password")
    private String password;

    /** 全局id */
    @Column(name = "open_id",nullable = false)
    private String openId;

    /** 昵称 */
    @Column(name = "nick_name")
    private String nickName;

    /** 头像地址 */
    @Column(name = "photo")
    private String photo;

    /** 用户类型 */
    @Column(name = "type")
    private Integer type;

    /** 创建时间 */
    @CreatedDate
    // @UpdateTimestamp
    // @CreatedBy
    @Column(name = "create_time",nullable = false)
    private Date createTime;

    @Transient
    private String accessToken;


    @Transient
    private String refreshToken;

    @Transient
    private String session_key;

    public String getSession_key() {
        return session_key;
    }

    public void setSession_key(String session_key) {
        this.session_key = session_key;
    }

    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    public String getRefreshToken() {
        return refreshToken;
    }

    public void setRefreshToken(String refreshToken) {
        this.refreshToken = refreshToken;
    }

    public TbUser() {
    }

    public TbUser(Integer userId, String userName, String moblie, String password, String openId, String nickName, String photo, Integer type, Date createTime) {
        this.userId = userId;
        this.userName = userName;
        this.moblie = moblie;
        this.password = password;
        this.openId = openId;
        this.nickName = nickName;
        this.photo = photo;
        this.type = type;
        this.createTime = createTime;
    }

    public TbUser(String openId, Integer type) {
        this.openId = openId;
        this.type = type;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getMoblie() {
        return moblie;
    }

    public void setMoblie(String moblie) {
        this.moblie = moblie;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return new HashSet<>();
    }

    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return this.openId;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getOpenId() {
        return openId;
    }

    public void setOpenId(String openId) {
        this.openId = openId;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getPhoto() {
        return photo;
    }

    public void setPhoto(String photo) {
        this.photo = photo;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
}
